home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 24 / vmode.zip / VMODE.ASM next >
Assembly Source File  |  1986-07-06  |  11KB  |  386 lines

  1.     page 58,132
  2.     title VMODE -- An Enhanced Video Mode Utility
  3.     name ADVMODE
  4.  
  5. comment    *
  6.  
  7.     This program will set the video mode to all possible settings.
  8.     It can be menu or command-line driven.  
  9.     *
  10.     
  11. ;----------------------------
  12. ;    Define required Equates
  13.  
  14.     STDIN    equ    0
  15.     STDOUT    equ    1
  16.     STDERR    equ    2
  17.     BLNK    equ    20h
  18.     EOS    equ    0
  19.     TAB    equ    9
  20.     LF    equ    0ah
  21.     CR    equ    0dh
  22.     TERM    equ    '$'
  23.         
  24. ;----------------------------
  25. ;    Define required MACROS
  26.  
  27. @EXIT    macro    RTNCODE            ;; Terminate program with return code
  28.     mov    ax,4c&RTNCODE&h        ; Request term with return code
  29.     int    21h            ; Call PC-DOS
  30.     endm
  31.  
  32. @READ    macro    BUFFER,FH        ;; DOS 2.0+ Read from File Macro
  33.     lea    dx,BUFFER        ; Load Buffer addr in DX
  34.     mov    cx,BUFFER&_LEN        ; Load Buffer Length in CX
  35.     mov    bx,FH            ; Load File/Device Handle in BX
  36.     mov    ah,3fh            ; Request DOS read
  37.     int    21h            ; Call PC-DOS
  38.     endm
  39.  
  40. @WRITE    macro    STRING,FH        ;; DOS 2.0+ Write to File Macro
  41.     lea    dx,STRING        ; Load String addr in DX
  42.     mov    cx,STRING&_LEN        ; Load String Length in CX
  43.     mov    bx,FH            ; Load File Handle in BX
  44.     mov    ah,40h            ; Request DOS write to file/device
  45.     int    21h            ; Call PC-DOS
  46.     endm
  47.  
  48. GRP    group    CSEG,DSEGA,DSEGB        ; All segments in same segment
  49.     assume    cs:GRP,ds:GRP,es:GRP,ss:GRP
  50.  
  51. DSEGB    segment byte public 'STRING'
  52.  
  53.     public    LOGO, CRLF, MENU, PROBLEM, INVALID, DOS_ERR, QUERY
  54.     
  55. LOGO    db    CR,LF,'Video MODE -- A Enhanced Video Mode Setting Utility V1.0'
  56.     db    CR,LF,'Copyright 1968 -- MoonWare   ALL RIGHTS RESERVED'
  57. CRLF    label    byte
  58.     db    CR,LF,LF
  59. CRLF_LEN equ    $ - CRLF
  60. LOGO_LEN equ    $ - LOGO
  61. MENU    db    'Mode  Type      Size   Colors    Adapter',CR,LF
  62.     db    '  0   Text      40x25  16(gray)  CGA,EGA,PCjr',CR,LF
  63.     db    '  1   Text      40x25  16/8      CGA,EGA,PCjr',CR,LF
  64.     db    '  2   Text      80x25  16(gray)  CGA,EGA,PCjr',CR,LF
  65.     db    '  3   Text      80x25  16/8      CGA,EGA,PCjr',CR,LF
  66.     db    '  4   Graphics 320x200 4         CGA,EGA,PCjr',CR,LF
  67.     db    '  5   Graphics 320x200 4(gray)   CGA,EGA,PCjr',CR,LF
  68.     db    '  6   Graphics 640x200 2         CGA,EGA,PCjr',CR,LF
  69.     db    '  7   Text      80x25  b\w       EGA,MA',CR,LF
  70.     db    '  8   Graphics 160x200 16        PCjr',CR,LF
  71.     db    '  9   Graphics 320x200 16        PCjr',CR,LF
  72.     db    ' 10   Graphics 640x200 4         PCjr',CR,LF
  73.     db    ' 13   Graphics 320x200 16        EGA',CR,LF
  74.     db    ' 14   Graphics 640x200 16        EGA',CR,LF
  75.     db    ' 15   Graphics 640x350 b\w       EGA',CR,LF
  76.     db    ' 16   Graphics 640x350 64        EGA',CR,LF
  77.     db    LF,'Enter desired mode: '
  78. MENU_LEN equ    $ - MENU
  79. QUERY    db    ' ?: '
  80. QUERY_LEN equ    $ - QUERY
  81. DOS_ERR db    CR,LF,'VMODE:  Need DOS 2.0+',CR,LF,TERM
  82. INVALID    db    CR,LF,'VMODE:  Invalid Mode',CR,LF,TAB,'Aborting...',CR,LF,LF
  83. INVALID_LEN equ    $ - INVALID
  84. PROBLEM db    'ERROR:  Video Mode was not properly set'
  85. PROBLEM_LEN equ $ - PROBLEM
  86.     db    '***** 6 July 1986 -- Raymond Moon *****'
  87. DSEGB    ends
  88.  
  89. DSEGA    segment byte public 'DATA'
  90.  
  91.     public    BUFFER, MODE
  92.     
  93. BUFFER    db    5 dup (?)
  94. BUFFER_LEN equ    $ - BUFFER
  95. MODE    dw    ?            ; Value for the Video Mode
  96. DSEGA    ends
  97.  
  98. CSEG    segment para public 'CODE'
  99.  
  100. ;-----------------------------
  101. ;    Define all procedures as public for debugging
  102.  
  103.     public MAIN, DISPLAY_MENU, ABORT, CMDLN, CONVERT, VALID
  104.     public PRINT_QUERY, SET_MODE
  105.  
  106.     public    PARMS, PARM_LEN
  107.         
  108. ;-----------------------------
  109. ;    Define Command Line arguments located in the PSP
  110.  
  111.     org     80h
  112.     PARM_LEN db     ?
  113.     PARMS   db      127 dup(?)
  114.  
  115. ;-----------------------------
  116. ;    MAIN procedure parses the Command Line 
  117.  
  118.     org    100h            ; .COM file format
  119. MAIN    proc    near
  120.     mov    ah,30h            ; Request DOS Version
  121.     int    21h            ; Call PC-DOS
  122.     cmp    al,2            ; Is it 2 or better
  123.     jae    MN0            ; OK, continue
  124.     mov    ah,9            ; Request DOS Print
  125.     lea    dx,DOS_ERR        ; Load addr of message in DX
  126.     int    21h            ; Call PC-DOS
  127.     int    20h            ; Terminate the program
  128. MN0:    cmp    PARM_LEN,0        ; Are there any Command Line arguments
  129.     jne    MN1            ; Yes, process them
  130.     call    DISPLAY_MENU        ; No, go to DISPLAY_MENU
  131. MN1:    xor    cx,cx            ; Null CX
  132.     push    cx            ; This ensures last *argv ends in NUL
  133.     mov    cl,PARM_LEN        ; Get # of bytes in Command Line
  134.     inc    cl            ; Increment CL to ensure round up
  135.     and    cx,0feh            ; Force an even count
  136.     mov    ax,sp            ; Get SP  
  137.     mov    bp,sp            ; Set BP to last byte of Cmd Ln
  138.     sub    ax,cx            ; Subtract PARM_LEN
  139.     mov    sp,ax            ; Reset SP, room on Stack
  140.     lea    si,PARMS        ; Load source addr in SI
  141.     mov    di,sp            ; Load destin addr in DI
  142.     cld                ; Ensure Direction Flag is up
  143.     rep    movsb            ; Move Command Line onto the Stack
  144.  
  145. ;-----------------------------
  146. ;    Convert all blanks in the Command Line to Nul
  147.  
  148.     mov    bx,bp            ; BX points to last byte of Cmd Ln
  149. MN2:    mov    al,[bx]            ; Get byte
  150.     cmp    al,BLNK            ; Is it a blank?
  151.     ja    MN3            ; No, go set up to get another
  152.     xor    al,al            ; Nul AX
  153.     mov    [bx],al            ; Store Nul in [BX]
  154. MN3:    dec    bx            ; BX point to next byte
  155.     cmp    bx,sp            ; Are we through yet?
  156.     jnb    MN2            ; No, go one mo' 'gin
  157.                     
  158. ;-----------------------------
  159. ;    Build *argv[].  argc kept in CX.  DX used as IN_WORD flag
  160.  
  161.     xor    cx,cx            ; Set CX (argc) to 0
  162.     xor    dx,dx            ; Set DX to NOT_INWORD
  163.     mov    bx,bp            ; BX point to last byte
  164.     mov    bp,sp            ; BP now points to Top of Stack
  165. MN4:    mov    al,[bx]            ; Get byte
  166.     cmp    al,0            ; Is it Nul?
  167.     jne    MN5            ; No, it is a char
  168.     cmp    dx,0            ; Was the last byte not a char?
  169.     je    MN6            ; Yes, go on with the processing
  170.     xor    dx,dx            ; No, it was a char.  Clear INWORD.
  171.     inc    cx            ; Increment argc
  172.     inc    bx            ; BX points to Cmd Ln arg
  173.     push    bx            ; Push addr onto stack
  174.     dec    bx            ; Reset BX
  175.     jmp    short MN6        ; Go set up for another byte
  176. MN5:    inc    dx            ; Set DX to INWORD     
  177. MN6:    dec    bx            ; BX point to next byte
  178.     cmp    bx,bp            ; Are we at the 1st byte yet?
  179.     jnb    MN4            ; No, go process another
  180.  
  181. ;-----------------------------
  182. ;    Set up for and call CMDLN
  183.  
  184.     push    cx            ; Push ARGC onto stack
  185.     call    CMDLN            ; Call Cmd Ln processor
  186. MAIN    endp
  187.     
  188. ;----------------------------
  189. ;    DISPLAY_MENU will display the LOGO and MENU, read in the desired mode,
  190. ;    and process the response for appropriateness.
  191.  
  192. DISPLAY_MENU    proc    near
  193.     @WRITE    LOGO,STDOUT        ; Print LOGO
  194.     @WRITE    MENU,STDOUT        ; Print MENU
  195. DM1:    @READ    BUFFER,STDIN        ; Get response
  196.     call    CONVERT
  197.  
  198. ;----------------------------
  199. ;    Was the response a number?
  200.  
  201.     jnc    DM2            ; CONVERT returned ok
  202.     call    PRINT_QUERY        ; Display QUERY
  203.     jmp    DM1            ; Try again
  204.     
  205. ;----------------------------
  206. ;    Ensure desired mode is valid.
  207.  
  208. DM2:    call    VALID
  209.     jnc    DM3            ; OK, continue
  210.     call    PRINT_QUERY        ; Display Query
  211.     jmp    DM1            ; Try again
  212.     
  213. ;---------------------------
  214. ;    Menu is finished, Call SET_MODE
  215.  
  216. DM3:    call    SET_MODE
  217.  
  218. DISPLAY_MENU endp
  219.  
  220. ;----------------------------
  221. ;    This procedure prints QUERY on the screen.
  222.  
  223. PRINT_QUERY    proc    near
  224.     @WRITE    QUERY,STDERR
  225.     ret
  226. PRINT_QUERY    endp
  227.  
  228. ;----------------------------
  229. ;    This procedure checks to see if the response was valid, 0-10 & 13-16.
  230.  
  231. VALID    proc    near
  232.     cmp    MODE,11            ; Is MODE = 11?
  233.     je    VD1            ; Yes, go to error return
  234.     cmp    MODE,12            ; Is MODE = 12?
  235.     je    VD1            ; Yes, go to error return
  236.     cmp    MODE,16            ; Is MODE > 16?
  237.     ja    VD1            ; Yes, go to error return
  238.     clc                ; Clear carry flag
  239.     ret                ; Return with valid response
  240. VD1:    stc                ; Set carry flag
  241.     ret                ; Return with invalid response
  242. VALID    endp
  243.  
  244. ;----------------------------
  245. ;    This procedure processes the command line
  246.  
  247. CMDLN_PARMS struc            ; CMDLN passed parameter addr struc
  248.     dw    ?,?            ; Saved BP and IP
  249. ARGC    dw    ?
  250. ARGV    dw    ?
  251. CMDLN_PARMS ends
  252.  
  253. CMDLN    proc    near
  254.     push    bp            ; Std entry logic
  255.     mov    bp,sp
  256.     
  257. ;----------------------------
  258. ;    Transfer ARGV[1] to BUFFER
  259.  
  260.     lea    di,BUFFER        ; Load addr of BUFFER in DI
  261.     mov    si,[bp].ARGV        ; Load addr of CMDLN arg in SI
  262.     mov    cx,25            ; Max len in CX
  263. CN1:    lodsb                ; Get next char
  264.     cmp    al,EOS            ; Is it EOS?
  265.     je    CN3            ; Yes, stop
  266.     stosb                ; Store it
  267.     dec    cx            ; Decrement CX
  268.     jcxz    CN2            ; Gone too far, input invalid
  269.     jmp    CN1            ; Continue
  270. CN2:    call    ABORT            ; Error out
  271.  
  272. ;----------------------------
  273. ;    Convert it to binary and check for a valid response.
  274.  
  275. CN3:    call    CONVERT            ; Convert it
  276.     jnc    CN4            ; Good, continue
  277.     call    ABORT            ; No, Error out
  278.     
  279. ;----------------------------
  280. ;    Check to see if response was valid.
  281.  
  282. CN4:    call    VALID
  283.     jnc    CN5            ; Yes, continue
  284.     call    ABORT            ; No, Error out
  285.     
  286. ;---------------------------
  287. ;    Input is valid, Go set mode
  288.  
  289. CN5:    call    SET_MODE
  290.  
  291. CMDLN    endp
  292.  
  293. ;----------------------------
  294. ;    This procedure aborts the program when in the Command Line mode.
  295. ;    An error message is printed and the program terminated with a
  296. ;    return code of 1.
  297.  
  298. ABORT    proc    near
  299.     @WRITE    INVALID,STDERR        ; Let user know somethings wrong
  300.     @EXIT    01            ; Terminate with indicated code
  301. ABORT    endp
  302.  
  303. ;----------------------------
  304. ;    This procedure sets the video mode and checks to see if it was 
  305. ;    properly set.
  306.  
  307. SET_MODE proc    near
  308.     mov    ax,MODE            ; Put MODE into AX
  309.     int    10h            ; Call VIDEO_IO (ROM BIOS)
  310.     mov    ah,0fh            ; Request video mode
  311.     int    10h            ; Call VIDEO_IO (ROM BIOS)
  312.     xor    ah,ah            ; Nul AH
  313.     cmp    ax,MODE            ; Are they the same?
  314.     jne    SM1            ; No, go tell the user
  315.  
  316. ;----------------------------
  317. ;    Display LOGO as sign of every thing OK and terminate program.
  318.  
  319.     @WRITE    LOGO,STDOUT        ; Display LOGO
  320.     @EXIT    00            ; Terminate 
  321.     
  322. ;----------------------------
  323. ;    Let user know that there was a problem, and terminate.
  324.  
  325. SM1:    @WRITE    LOGO,STDERR        ; Display LOGO
  326.     @WRITE    PROBLEM,STDERR        ; Display Error message
  327.     @EXIT    01            ; Terminate with return code
  328.     
  329. SET_MODE endp
  330.  
  331. ;----------------------------
  332. ;    This procedure converts the ASCII string in buffer into a binary
  333. ;    integer in MODE.  If any errors are detected, the procedure returns
  334. ;    with the Carry Flag set.
  335.  
  336. CONVERT    proc    near
  337.  
  338. ;----------------------------
  339. ;    Set up for conversion loop.  Buffer length starts in CX.  BH is 
  340. ;    used as INWORD flag.
  341.  
  342.     mov    cx,5            ; Put BUFFER length in CX
  343.     mov    bx,000ah        ; INWORD flag = FALSE, BL = 10
  344.     xor    dx,dx            ; Clear DX
  345.     mov    ax,dx            ; Clear AX
  346.     lea    si,BUFFER        ; SI => BUFFER
  347.     
  348. ;----------------------------
  349. ;    Start conversion.
  350.  
  351. CT1:    lodsb                ; Get next char
  352.     sub    al,'0'            ; Convert to number
  353.     jb    CT2            ; Was below '0', not INWORD yet
  354.     cmp    al,9            ; Is it or below?
  355.     ja    CT2            ; It wasn't a number, not INWORD yet
  356.     xchg    al,dl            ; Save it
  357.     mul    bl            ; Multiply by 10
  358.     add    dl,al            ; Add new value
  359.     inc    bh            ; Ensure INWORD is set
  360.     jmp    short CT3        ; Jump to loop inst
  361. CT2:    cmp    bh,0            ; Is INWORD set?
  362.     jne    CT4            ; Yes, we're finished
  363. CT3:    loop    CT1            ; Go again
  364.  
  365. ;----------------------------
  366. ;    If the program got here with INWORD = FALSE, there was a problem.
  367. ;    Return error.
  368.  
  369.     cmp    bh,0            ; Is INWORD set?
  370.     jne    CT4            ; No, we're OK
  371.     stc                ; Set Carry Flag
  372.     ret
  373.  
  374. ;----------------------------
  375. ;    Put result into MODE and return.
  376.  
  377. CT4:    mov    MODE,dx            ; Store result
  378.     clc                ; Ensure Carry Flag is clear
  379.     ret
  380.     
  381. CONVERT    endp
  382.  
  383. CSEG    ends
  384.  
  385.     end    MAIN
  386.